<!DOCTYPE html>
<html lang="zh-Hans-CN">
<head>
  <% include("/include/header3.html",{"title":"开发_字典编辑页"}){} %>
</head>
<body>

<div id="app">
  <div class="mainBox ">
    <div class="main-container layui-card">
      <div class="layui-card-body">

         <t-form ref="formRef" :data="form" :rules="rules" :disabled="loading" scroll-to-first-error="smooth" colon requiredMark>
           <t-row :gutter="[50,20]">
            <t-col :xs="12" :sm="6">
              <t-form-item label="父节点" name="pid">
                <t-input v-model="form.pid" placeholder="请输入父节点" :maxlength="19" show-limit-number clearable></t-input>
              </t-form-item>
            </t-col>
            <t-col :xs="12" :sm="6">
              <t-form-item label="字典父节点列表" name="pids">
                <t-input v-model="form.pids" placeholder="请输入字典父节点列表" :maxlength="500" show-limit-number clearable></t-input>
              </t-form-item>
            </t-col>
            <t-col :xs="12" :sm="6">
              <t-form-item label="名称" name="name">
                <t-input v-model="form.name" placeholder="请输入名称" :maxlength="50" show-limit-number clearable></t-input>
              </t-form-item>
            </t-col>
            <t-col :xs="12" :sm="6">
              <t-form-item label="字典值" name="value">
                <t-input v-model="form.value" placeholder="请输入字典值" :maxlength="50" show-limit-number clearable></t-input>
              </t-form-item>
            </t-col>
            <t-col :xs="12" :sm="6">
              <t-form-item label="字典标识" name="code">
                <t-input v-model="form.code" placeholder="请输入字典标识" :maxlength="50" show-limit-number clearable></t-input>
              </t-form-item>
            </t-col>
            <t-col :xs="12" :sm="6">
              <t-form-item label="级别" name="level">
                <t-input v-model="form.level" placeholder="请输入级别" :maxlength="10" show-limit-number clearable></t-input>
              </t-form-item>
            </t-col>
            <t-col :xs="12" :sm="6">
              <t-form-item label="排序" name="sort">
                <t-input v-model="form.sort" placeholder="请输入排序" :maxlength="10" show-limit-number clearable></t-input>
              </t-form-item>
            </t-col>
            <t-col :xs="12" :sm="6">
              <t-form-item label="状态（1-启用，2-未启用）" name="status">
                <t-input v-model="form.status" placeholder="请输入状态（1-启用，2-未启用）" :maxlength="1" show-limit-number clearable></t-input>
              </t-form-item>
            </t-col>
          </t-row>
        </t-form>

      </div>
    </div>
  </div>
  <div class="bottom">
    <t-space class="button-container ">
      <t-button :loading="loading" theme="primary" @click="onSave"><i class="layui-icon layui-icon-ok mr-5 text-size-14"></i>保存</t-button>
      <t-button theme="warning" @click="closeBtn.close"><i class="layui-icon mr-5 text-size-14" :class="closeBtn.i"></i>{{closeBtn.t}}</t-button>
    </t-space>
  </div>
</div>

<script>
  const PATH_URL = "dev/dict/";
</script>

<script>

  setupVue("#app", {
    setup() {
      // 表单相关
      const loading = Vue.ref(false);
      const formRef = Vue.ref(null);
      const form = Vue.ref({
        pid: null,
        pids: null,
        name: null,
        value: null,
        code: null,
        level: null,
        sort: null,
        status: null,
      });
      const rules = {
        pid: [$required('请输入父节点')],
        name: [$required('请输入名称')],
        code: [$required('请输入字典标识')],
      };
      // 获取表单数据
      const getForm = (id) => req(axiosGet, PATH_URL + "getInfo", {id}, (res) => {
        if (res.code === 200) {
          form.value = res.data;
        } else {
          $baseAlert(res.msg, () => closeBtn.value.close());
        }
      }, loading);
      const LyData = getLayerData();
      if (LyData && LyData.id) getForm(LyData.id);
      else {

      }


      // 点击保存
      const onSave = () => {
        formRef.value.validate().then((validateResult) => {
          if (validateResult && Object.keys(validateResult).length) {
            const firstError = Object.values(validateResult)[0]?.[0]?.message;
            $baseMsg(firstError);
          } else {
            let REQ;
            let URL;
            if (form.value.id) {
              REQ = axiosPut, URL = PATH_URL + "update";
            } else {
              REQ = axiosPost, URL = PATH_URL + "add";
            }
            req(REQ, URL, form, (res) => {
              $baseAlert(res.msg, () => {
                if (res.code === 200) closeLayer(parent.reloadData);
              })
            }, loading);
          }
        });
      }

      const closeBtn = useCloseBtn();
      return {
        closeBtn,
        formRef, loading, form, rules,
        onSave,

      }

    }
  });
</script>


</body>
</html>
